libxl: event system: properly register the SIGCHLD self-pipe
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 5 Nov 2013 17:32:06 +0000 (17:32 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 21 Nov 2013 18:47:24 +0000 (18:47 +0000)
commite5b94170fddd1644edfd6ebd9f4a312e0e416883
tree0b220bdd14be683927169e5362d470d6728b5ee5
parent755aa9edb274f6f69a7afaffa399c70eb8205369
libxl: event system: properly register the SIGCHLD self-pipe

An application which uses libxl_osevent_register_hooks, and doesn't
use libxl_sigchld_owner_mainloop, would never properly experience the
deaths of its (libxl) children.

This is because the SIGCHLD self pipe would be handled using ad-hoc
code in beforepoll_internal and afterpoll_internal.  However, this is
no good if application is using the fd registration system instead; in
that case these functions would not be called and nothing would deal
with readability of the self pipe.

Fix this as follows:

The SIGCHLD self pipe now is now dealt with by a standard libxl__ev_fd
handler, which is registered and deregistered along with the SIGCHLD
handler itself.  The handler function subsumes the ad-hoc response
code removed from beforepoll_internal, and the functionality of
libxl__fork_selfpipe_woken.

This is also tidier as the SIGCHLD self pipe is no longer touched
outside libxl_fork.c other than in ctx initialisation and teardown.

(The ad-hoc arrangements for poller->wakeup_pipe in
beforepoll_internal and afterpoll_internal are OK because the
libxl__poller mechanism exists to wake up threads which are sitting
inside libxl's poll loop, so is not applicable to the application's
event loop.)

Reported-by: Bamvor Jian Zhang <bjzhang@suse.com>
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Bamvor Jian Zhang <bjzhang@suse.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Jim Fehlig <jfehlig@suse.com>
tools/libxl/libxl.c
tools/libxl/libxl_event.c
tools/libxl/libxl_fork.c
tools/libxl/libxl_internal.h